package Leetcode.lc069;

/***
 *x的平方根，二分，本质上搜索根
 */
public class Sloution {
    public int mySqrt(int x) {
       int lef=1;
       int right=x;
       while(lef<=right){
           int mid=lef+(right-lef)/2;
           if(mid==x/mid){
               return mid;
           } else if (mid>x/mid) {
               right=mid-1;
           }else{
               lef=mid+1;
           }
       }
       return lef-1;
    }

    public static void main(String[] args) {
        Sloution sloution = new Sloution();
        int i = sloution.mySqrt(8);
        System.out.println(i);

    }
}
